package cn.ycl.netty.nio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

/**
 * @Author YuanChangLiang
 * @Date 2021/1/8 11:39
 * NIO拷贝图片
 */
public class NioCopyImage {
    public static void main(String[] args) throws IOException {
        //创建相关的流
        FileInputStream fileInputStream = new FileInputStream("E:\\all_file\\a.jpg");
        FileOutputStream fileOutputStream = new FileOutputStream("E:\\all_file\\a2.jpg");

        //获取各个流对应的filechannel
        FileChannel channel = fileInputStream.getChannel();
        FileChannel channel1 = fileOutputStream.getChannel();

        //使用transferForm完成拷贝
        channel1.transferFrom(channel,0,channel.size());

        //关闭流和通道
        fileInputStream.close();
        fileOutputStream.close();
        channel.close();
        channel1.close();

    }


}
